'''
https://leetcode.cn/problems/minimum-number-of-operations-to-make-arrays-similar/description/
'''
import bisect
from typing import List

class Solution:
    def makeSimilar(self, nums: List[int], target: List[int]) -> int:
        nums.sort()
        target.sort()
        n = len(nums)
        a, b, c, d = [], [], [], []
        for i in range(n):
            if nums[i] & 1 == 0:
                a.append(nums[i])
            else:
                b.append(nums[i])
            if target[i] & 1 == 0:
                c.append(target[i])
            else:
                d.append(target[i])

        different = 0
        for i in range(len(a)):
            different += abs(a[i] - c[i])
        for i in range(len(b)):
            different += abs(b[i] - d[i])
        return different // 4

nums = [2, 11, 1, 16]
target = [6,5,12,7]
print(Solution().makeSimilar(nums, target))